#include "stdafx.h"
#include "BlendState.h"

namespace Reign
{namespace Video
{namespace D3D10
{
	#pragma region Constructors
	BlendState::BlendState(DisposableI^ parent, BlendStateDescI^ desc)
	: Disposable(parent)
	{
		null();
		try
		{
			video = parent->FindParentOrSelfWithException<Video^>();

			ID3D10BlendState* blendStateTEMP;
			BlendStateDesc^ descTEMP = (BlendStateDesc^)desc;
			if (FAILED(video->Device->CreateBlendState(descTEMP->Desc, &blendStateTEMP)))
			{
				Debug::ThrowError(L"BlendState", L"Failed to create BlendState");
			}
			blendState = blendStateTEMP;
		}
		catch (Exception^ ex)
		{
			delete this;
			throw ex;
		}
	}

	BlendState::~BlendState()
	{
		disposeChilderen();
		if (blendState) blendState->Release();
		null();
	}

	void BlendState::null()
	{
		blendState = 0;
	}
	#pragma endregion
	
	#pragma region Methods
	void BlendState::Enable()
	{
		ID3D10BlendState* blendStateTEMP = blendState;
		video->Device->OMSetBlendState(blendStateTEMP, 0, 0xffffffff);
	}
	#pragma endregion
}
}
}